package com.gaofeng.day03;

public class repeat {
    public static void main(String[] args) {
        /**
         * Repeats the given string `n` times.
         * * repeat('*', 3)
         * // => '***'
         *
         * repeat('abc', 2)
         * // => 'abcabc'
         *
         * repeat('abc', 0)
         * // => ''
         **/
        String str = repeat("*",3);
        System.out.println(str);
        String str1 = repeat("abc",2);
        System.out.println(str1);
        String str2 = repeat("abc",0);
        System.out.println(str2);
    }
    public static String repeat(String string,int n){
        String result = "";
        if(string.isEmpty() || n < 1 || n > Integer.MAX_VALUE){
            return  result;
        }

        do {
            if(n % 2 > 0){
                result +=string;
            }
            n = (int)(Math.floor( n / 2));
            if(n > 0){
                string += string;
            }
        }while (n > 0);
        return  result;
    }
}
